package pl.edu.agh.ssm.monitor.parsers.rtcp;

import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.util.LinkedList;

import jlibrtp.CompRtcpPkt;
import jlibrtp.RTPSession;
import jlibrtp.RtcpPkt;

public class RTCPParser {

	private RTPSession session;
	private InetSocketAddress address;
	
	public RTCPParser() {
		try {
			session = new RTPSession(new DatagramSocket(), new DatagramSocket());
			address = new InetSocketAddress(0);
		} catch (SocketException e) {
			e.printStackTrace();
		} 
	}
	
	public LinkedList<RtcpPkt> parse(byte[] data) {
		CompRtcpPkt compRtcpPkt = new CompRtcpPkt(data, data.length, address, session);
		if(compRtcpPkt.problem != 0) {
			return new LinkedList<RtcpPkt>(); //return empty list
		}
		return compRtcpPkt.getRtcpPkts();
	}
	
}
